package cn.lzj.ymcc.web.controller;

import cn.lzj.ymcc.dto.SmsCodeDto;
import cn.lzj.ymcc.result.JSONResult;
import cn.lzj.ymcc.service.ISmsCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifycode")
public class SmsSendController {

    @Autowired
    private ISmsCodeService smsCodeService;

    @PostMapping("/sendSmsCode")
    public JSONResult sendSmsCode(@RequestBody @Valid SmsCodeDto smsCodeDto) {
        smsCodeService.sendSmsCode(smsCodeDto);
        return JSONResult.success();
    }

    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult imageCode(@PathVariable("imageCodeKey") String imageCodeKey) {
        String base64Str = smsCodeService.imageCode(imageCodeKey);
        return JSONResult.success().setData(base64Str);
    }
}
